<template>
  <div>
    <el-row>
      <el-col :span="8" >
        <h4 style="margin:0">
          <span>标签管理</span>
          <el-button class="addBtn" type="primary" @click="dialogVisible = true">添加标签</el-button>
        </h4>
      </el-col>
      <el-col :span="16" style="text-align:right;position:relative,;z-index:999" >
        <span v-show="checkleng.length>0 && userRole.DN_201002" style="position:absolute;right:10px;">
 
          <el-button class="addBtn" type="danger" @click="deleteFun">清空</el-button>
        </span>
      </el-col>
    </el-row>
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="视频标签" name="first">
        <Info v-if="navStatus == 0" ref="refData" @editRow='editRow' :navStatus="navStatus"></Info>
      </el-tab-pane>

      <el-tab-pane label="问题标签" name="second">
        <Info  v-if="navStatus == 1"  ref="refData"  @editRow='editRow' :navStatus="navStatus"></Info>
      </el-tab-pane>
    </el-tabs>

    <el-dialog title="添加标签" :visible.sync="dialogVisible" width="36%" :before-close="handleClose">
      <div>
        <el-form label-position="right" label-width="80px" :model="formLabelAlign">
          <el-form-item label="类型">
            <el-select v-model="formLabelAlign.type" placeholder="请选择">
              <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="标签名">
            <el-input v-model="formLabelAlign.markName"></el-input>
          </el-form-item>
          <el-form-item label="色值">
            <el-input v-model="formLabelAlign.color"></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose">取 消</el-button>
        <el-button type="primary" @click="addMarkDialog">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>  
  import Info from './Markinfo/Info'
  import Http from '@/Http/Http'
  export default {
    data() {
      return {
        userRole:JSON.parse(sessionStorage.getItem('userSolt')),
        dialogVisible:false,
        activeName: 'first',
        checkleng:'',
        formLabelAlign: {
          type:3,
          markName: '',
          color: ''
        },
        options:[{value:3,label:'视频'},{value:4,label:'问题'}],
        tableData: [],
        navStatus:0,
        id:'',
      }
    },
   
    components:{ Info },
    mounted() {
      var obj = document.getElementById('centerbox')
      obj.addEventListener('scroll', this.handleScroll,true)
    },
    destroyed(){
      var obj = document.getElementById('centerbox')
      obj.removeEventListener('scroll', this.handleScroll,true)
    },
    methods: {
      handleScroll() {
        var scollobj = document.getElementById('centerbox');
        var scrollTop = scollobj.scrollTop;
        const obj = document.getElementById('tab-first');
        const myobj = obj.parentNode.parentNode;
        if(scrollTop> 32){
          myobj.style.position = 'fixed';
          myobj.style.top = 0;
        } else {
          myobj.style.position = 'relative';
        }
        
      },
      handleClick(tab, event) {
       this.navStatus = tab.index;
      },
      addMarkDialog() {
        const obj = {
          name:this.formLabelAlign.markName,
          type:this.formLabelAlign.type,
          color:this.formLabelAlign.color
        }
        this.id ? this.editFun(obj) : this.addFun(obj);
        this.dialogVisible = false;
        this.formLabelAlign.markName = '';
        this.formLabelAlign.color = '';
      },
      addFun(obj) {
        Http.addMark(obj)
        .then(res => {
          if (res.data.code == 200) {
            this.$message.success('添加成功')
            this.$refs.refData.getlist()
          } else {
            this.$message.error('添加失败')
          }
        })
        .catch( error => {
          
        })
      },
      editFun(obj) {
        obj.id = this.id;
        Http.editMark(obj)
        .then(res => {
          this.id = '';
          if (res.data.code == 200) {
            this.$message.success('修改成功')
            this.$refs.refData.getlist()
          } else {
            this.$message.error('添加失败')
          }
        })
        .catch( error => {
          
        })
      },
      handleClose() {
        this.dialogVisible = false;
        this.formLabelAlign.markName = '';
        this.formLabelAlign.color = '';
      },
      editRow(row) {
        this.formLabelAlign.type = row.type;
        this.formLabelAlign.markName = row.name;
        this.formLabelAlign.color = row.color;
        this.id = row.id;
        this.dialogVisible = true;
      },
      deleteFun() {
      }
    }
  }
</script>
<style>
.el-tabs__nav-wrap::after{
  width:0!important;
}
</style>
